#求最大不重复字符串的长度
# 思路一旦重复，将坐标往左移，不重复继续扩大窗口
def length_of_longest_substring(s: str) -> int:
    char_set = set()
    left = 0
    max_length = 0
    
    for right in range(len(s)):
        while s[right] in char_set:
            char_set.remove(s[left])
            left += 1
        char_set.add(s[right])
        max_length = max(max_length, right - left + 1)
    
    return max_length

def find_max_length_str(s:str) -> int:
    char_set = set()
    left = 0
    max_len = 0
    for right in len(str):
        if s[right] in char_set:
            left += 1
            char_set.remove(s[right])
        char_set.add(s[right])
        max_len = max(max_len, right - left + 1)    
    return max_len
# 测试用例
if __name__ == "__main__":
    test_cases = [
        ("abcabcbb", 3),
        ("bbbbb", 1),
        ("pwwkew", 3),
        ("", 0),
        ("au", 2)
    ]
    
    for s, expected in test_cases:
        result = length_of_longest_substring(s)
        assert result == expected, f"Test case failed: {s} -> expected {expected}, got {result}"
    print("All test cases passed!")